﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfDemo.IRepository.Sys;
using WpfDemo.Models.Context;
using WpfDemo.Models.Sys;

namespace WpfDemo.Repository.Sys
{
    public class AuthRepository : BaseRepository<AuthEntity>, IAuthRepository
    {
        public AuthRepository(EfContext db) : base(db)
        {
        }

        public int Add(List<AuthEntity> entities, string RoleId)
        {           
           using (var db = new EfContext())
            {                
                var authLst = db.auths.Where(m => m.F_RoleId == RoleId).ToList();
                authLst.ForEach(m =>
                {
                    db.auths.Remove(m);
                });
                if(entities !=null && entities.Count > 0) {
                    db.auths.AddRange(entities);
                }               
                return db.SaveChanges();
            }
        }
    }
}
